/*
 * Te_Set_View.java
 *
 * Created on 2009年2月24日, 上午11:27
 */

package view;

import model.Set_Model;
import ucm.CheckSetting_UC;
import ucm.ShowResult_UC;
import ucm.SignIn_UC;

/**
 *
 * @author  马凯
 */
public class Te_Set_View extends javax.swing.JFrame {
    private static Te_Set_View tsv;
    /** Creates new form Te_Set_View */
    public Te_Set_View() {
        initComponents();
        this.setLocationRelativeTo(null);
    }
    
    public static Te_Set_View getInstance(){
        if(tsv==null){
            tsv = new Te_Set_View();
        }
        return tsv;
    }
    
    public Set_Model getSetModel(){
        Set_Model sm = new Set_Model();
        sm.setCan_Bu(can_Bu);
        sm.setOk_Bu(ok_Bu);
        sm.setSub_TF(sub_TF);
        sm.setTeID_TF(teID_TF);
        return sm;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Sub_La = new javax.swing.JLabel();
        sub_TF = new javax.swing.JTextField();
        can_Bu = new javax.swing.JButton();
        ok_Bu = new javax.swing.JButton();
        teID_La = new javax.swing.JLabel();
        teID_TF = new javax.swing.JTextField();
        result_Bu = new javax.swing.JButton();
        MenuBar = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ISC_SING IN");

        Sub_La.setText("Subject ID:");

        can_Bu.setText("Cancel");

        ok_Bu.setText("OK");
        ok_Bu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ok_BuActionPerformed(evt);
            }
        });

        teID_La.setText("Teacher_ID:");

        result_Bu.setText("Show result ");
        result_Bu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                result_BuActionPerformed(evt);
            }
        });

        jMenu1.setText("File");
        MenuBar.add(jMenu1);

        jMenu2.setText("Edit");
        MenuBar.add(jMenu2);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(Sub_La, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sub_TF, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(teID_La, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE))
                    .addComponent(result_Bu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ok_Bu, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                        .addComponent(can_Bu))
                    .addComponent(teID_TF, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Sub_La)
                    .addComponent(sub_TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(teID_TF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(teID_La))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok_Bu)
                    .addComponent(can_Bu)
                    .addComponent(result_Bu))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ok_BuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ok_BuActionPerformed
        if(CheckSetting_UC.getInstance(this.sub_TF.getText()).run()==1){
            SignIn_UC.getInstance(this).run();
        }else{
            this.getSetModel().getSub_TF().setText("");
        }
    }//GEN-LAST:event_ok_BuActionPerformed

    private void result_BuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_result_BuActionPerformed
        if(CheckSetting_UC.getInstance(this.sub_TF.getText()).run()==1){
            ShowResult_UC.getInstance(this.sub_TF.getText()).run();
        }else{
            this.getSetModel().getSub_TF().setText("");
        }
    }//GEN-LAST:event_result_BuActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Te_Set_View().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MenuBar;
    private javax.swing.JLabel Sub_La;
    private javax.swing.JButton can_Bu;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JButton ok_Bu;
    private javax.swing.JButton result_Bu;
    private javax.swing.JTextField sub_TF;
    private javax.swing.JLabel teID_La;
    private javax.swing.JTextField teID_TF;
    // End of variables declaration//GEN-END:variables
    
}
